package dao;


import java.math.BigDecimal;
import java.sql.Connection;
import java.util.ArrayList;
import java.util.Date;
import java.util.Collections;
import java.util.List;

import org.apache.commons.lang.ObjectUtils;
import org.apache.torque.TorqueException;
import org.apache.torque.om.BaseObject;
import org.apache.torque.om.ComboKey;
import org.apache.torque.om.DateKey;
import org.apache.torque.om.NumberKey;
import org.apache.torque.om.ObjectKey;
import org.apache.torque.om.SimpleKey;
import org.apache.torque.om.StringKey;
import org.apache.torque.om.Persistent;
import org.apache.torque.util.Criteria;
import org.apache.torque.util.Transaction;

  
    
  
/**
 * This class was autogenerated by Torque on:
 *
 * [Fri Jan 09 02:39:32 PST 2009]
 *
 * You should not use this class directly.  It should not even be
 * extended all references should be to EmployeeRank
 */
public abstract class BaseEmployeeRank extends BaseObject
{
    /** The Peer class */
    private static final EmployeeRankPeer peer =
        new EmployeeRankPeer();

        
    /** The value for the employeerankid field */
    private int employeerankid;
      
    /** The value for the employeeid field */
    private int employeeid;
      
    /** The value for the rankid field */
    private int rankid;
  
    
    /**
     * Get the Employeerankid
     *
     * @return int
     */
    public int getEmployeerankid()
    {
        return employeerankid;
    }

                        
    /**
     * Set the value of Employeerankid
     *
     * @param v new value
     */
    public void setEmployeerankid(int v) 
    {
    
                  if (this.employeerankid != v)
              {
            this.employeerankid = v;
            setModified(true);
        }
    
          
              }
  
    /**
     * Get the Employeeid
     *
     * @return int
     */
    public int getEmployeeid()
    {
        return employeeid;
    }

                              
    /**
     * Set the value of Employeeid
     *
     * @param v new value
     */
    public void setEmployeeid(int v) throws TorqueException
    {
    
                  if (this.employeeid != v)
              {
            this.employeeid = v;
            setModified(true);
        }
    
                          
                if (aEmployee != null && !(aEmployee.getEmployeeid() == v))
                {
            aEmployee = null;
        }
      
              }
  
    /**
     * Get the Rankid
     *
     * @return int
     */
    public int getRankid()
    {
        return rankid;
    }

                              
    /**
     * Set the value of Rankid
     *
     * @param v new value
     */
    public void setRankid(int v) throws TorqueException
    {
    
                  if (this.rankid != v)
              {
            this.rankid = v;
            setModified(true);
        }
    
                          
                if (aRank != null && !(aRank.getRankid() == v))
                {
            aRank = null;
        }
      
              }
  
      
    
                  
    
        private Employee aEmployee;

    /**
     * Declares an association between this object and a Employee object
     *
     * @param v Employee
     * @throws TorqueException
     */
    public void setEmployee(Employee v) throws TorqueException
    {
            if (v == null)
        {
                    setEmployeeid(0);
                  }
        else
        {
            setEmployeeid(v.getEmployeeid());
        }
                aEmployee = v;
    }

                                            
    /**
     * Get the associated Employee object
     *
     * @return the associated Employee object
     * @throws TorqueException
     */
    public Employee getEmployee() throws TorqueException
    {
        if (aEmployee == null && (this.employeeid > 0))
        {
                          aEmployee = EmployeePeer.retrieveByPK(SimpleKey.keyFor(this.employeeid));
              
            /* The following can be used instead of the line above to
               guarantee the related object contains a reference
               to this object, but this level of coupling
               may be undesirable in many circumstances.
               As it can lead to a db query with many results that may
               never be used.
               Employee obj = EmployeePeer.retrieveByPK(this.employeeid);
               obj.addEmployeeRanks(this);
            */
        }
        return aEmployee;
    }

    /**
     * Provides convenient way to set a relationship based on a
     * ObjectKey.  e.g.
     * <code>bar.setFooKey(foo.getPrimaryKey())</code>
     *
           */
    public void setEmployeeKey(ObjectKey key) throws TorqueException
    {
      
                        setEmployeeid(((NumberKey) key).intValue());
                  }
    
    
                  
    
        private Rank aRank;

    /**
     * Declares an association between this object and a Rank object
     *
     * @param v Rank
     * @throws TorqueException
     */
    public void setRank(Rank v) throws TorqueException
    {
            if (v == null)
        {
                    setRankid(0);
                  }
        else
        {
            setRankid(v.getRankid());
        }
                aRank = v;
    }

                                            
    /**
     * Get the associated Rank object
     *
     * @return the associated Rank object
     * @throws TorqueException
     */
    public Rank getRank() throws TorqueException
    {
        if (aRank == null && (this.rankid > 0))
        {
                          aRank = RankPeer.retrieveByPK(SimpleKey.keyFor(this.rankid));
              
            /* The following can be used instead of the line above to
               guarantee the related object contains a reference
               to this object, but this level of coupling
               may be undesirable in many circumstances.
               As it can lead to a db query with many results that may
               never be used.
               Rank obj = RankPeer.retrieveByPK(this.rankid);
               obj.addEmployeeRanks(this);
            */
        }
        return aRank;
    }

    /**
     * Provides convenient way to set a relationship based on a
     * ObjectKey.  e.g.
     * <code>bar.setFooKey(foo.getPrimaryKey())</code>
     *
           */
    public void setRankKey(ObjectKey key) throws TorqueException
    {
      
                        setRankid(((NumberKey) key).intValue());
                  }
       
                
    private static List fieldNames = null;

    /**
     * Generate a list of field names.
     *
     * @return a list of field names
     */
    public static synchronized List getFieldNames()
    {
        if (fieldNames == null)
        {
            fieldNames = new ArrayList();
              fieldNames.add("Employeerankid");
              fieldNames.add("Employeeid");
              fieldNames.add("Rankid");
              fieldNames = Collections.unmodifiableList(fieldNames);
        }
        return fieldNames;
    }

    /**
     * Retrieves a field from the object by name passed in as a String.
     *
     * @param name field name
     * @return value
     */
    public Object getByName(String name)
    {
          if (name.equals("Employeerankid"))
        {
                return new Integer(getEmployeerankid());
            }
          if (name.equals("Employeeid"))
        {
                return new Integer(getEmployeeid());
            }
          if (name.equals("Rankid"))
        {
                return new Integer(getRankid());
            }
          return null;
    }
    
    /**
     * Retrieves a field from the object by name passed in
     * as a String.  The String must be one of the static
     * Strings defined in this Class' Peer.
     *
     * @param name peer name
     * @return value
     */
    public Object getByPeerName(String name)
    {
          if (name.equals(EmployeeRankPeer.EMPLOYEERANKID))
        {
                return new Integer(getEmployeerankid());
            }
          if (name.equals(EmployeeRankPeer.EMPLOYEEID))
        {
                return new Integer(getEmployeeid());
            }
          if (name.equals(EmployeeRankPeer.RANKID))
        {
                return new Integer(getRankid());
            }
          return null;
    }

    /**
     * Retrieves a field from the object by Position as specified
     * in the xml schema.  Zero-based.
     *
     * @param pos position in xml schema
     * @return value
     */
    public Object getByPosition(int pos)
    {
            if (pos == 0)
        {
                return new Integer(getEmployeerankid());
            }
              if (pos == 1)
        {
                return new Integer(getEmployeeid());
            }
              if (pos == 2)
        {
                return new Integer(getRankid());
            }
              return null;
    }
     
    /**
     * Stores the object in the database.  If the object is new,
     * it inserts it; otherwise an update is performed.
     *
     * @throws Exception
     */
    public void save() throws Exception
    {
          save(EmployeeRankPeer.getMapBuilder()
                .getDatabaseMap().getName());
      }

    /**
     * Stores the object in the database.  If the object is new,
     * it inserts it; otherwise an update is performed.
       * Note: this code is here because the method body is
     * auto-generated conditionally and therefore needs to be
     * in this file instead of in the super class, BaseObject.
       *
     * @param dbName
     * @throws TorqueException
     */
    public void save(String dbName) throws TorqueException
    {
        Connection con = null;
          try
        {
            con = Transaction.begin(dbName);
            save(con);
            Transaction.commit(con);
        }
        catch(TorqueException e)
        {
            Transaction.safeRollback(con);
            throw e;
        }
      }

      /** flag to prevent endless save loop, if this object is referenced
        by another object which falls in this transaction. */
    private boolean alreadyInSave = false;
      /**
     * Stores the object in the database.  If the object is new,
     * it inserts it; otherwise an update is performed.  This method
     * is meant to be used as part of a transaction, otherwise use
     * the save() method and the connection details will be handled
     * internally
     *
     * @param con
     * @throws TorqueException
     */
    public void save(Connection con) throws TorqueException
    {
          if (!alreadyInSave)
        {
            alreadyInSave = true;


  
            // If this object has been modified, then save it to the database.
            if (isModified())
            {
                if (isNew())
                {
                    EmployeeRankPeer.doInsert((EmployeeRank) this, con);
                    setNew(false);
                }
                else
                {
                    EmployeeRankPeer.doUpdate((EmployeeRank) this, con);
                }
            }

                      alreadyInSave = false;
        }
      }


                    
      /**
     * Set the PrimaryKey using ObjectKey.
     *
     * @param  employeerankid ObjectKey
     */
    public void setPrimaryKey(ObjectKey key)
        
    {
            setEmployeerankid(((NumberKey) key).intValue());
        }

    /**
     * Set the PrimaryKey using a String.
     *
     * @param key
     */
    public void setPrimaryKey(String key) 
    {
            setEmployeerankid(Integer.parseInt(key));
        }

  
    /**
     * returns an id that differentiates this object from others
     * of its class.
     */
    public ObjectKey getPrimaryKey()
    {
          return SimpleKey.keyFor(getEmployeerankid());
      }

 

    /**
     * Makes a copy of this object.
     * It creates a new object filling in the simple attributes.
       * It then fills all the association collections and sets the
     * related objects to isNew=true.
       */
      public EmployeeRank copy() throws TorqueException
    {
        return copyInto(new EmployeeRank());
    }
  
    protected EmployeeRank copyInto(EmployeeRank copyObj) throws TorqueException
    {
          copyObj.setEmployeerankid(employeerankid);
          copyObj.setEmployeeid(employeeid);
          copyObj.setRankid(rankid);
  
                    copyObj.setEmployeerankid(0);
                        
        
        return copyObj;
    }

    /**
     * returns a peer instance associated with this om.  Since Peer classes
     * are not to have any instance attributes, this method returns the
     * same instance for all member of this class. The method could therefore
     * be static, but this would prevent one from overriding the behavior.
     */
    public EmployeeRankPeer getPeer()
    {
        return peer;
    }

    public String toString()
    {
        StringBuffer str = new StringBuffer();
        str.append("EmployeeRank:\n");
        str.append("Employeerankid = ")
           .append(getEmployeerankid())
           .append("\n");
        str.append("Employeeid = ")
           .append(getEmployeeid())
           .append("\n");
        str.append("Rankid = ")
           .append(getRankid())
           .append("\n");
        return(str.toString());
    }
}
